package com.goodving.guli.fragment;

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.activity.C1757t;
import com.goodving.guli.activity.HealthGoalsActivity;
import com.goodving.guli.activity.LoginActivity;
import com.goodving.guli.activity.PersonInfoSettingUnitActivity;
import com.goodving.guli.activity.SessionManager;
import com.goodving.guli.activity.StatisticActivity;
import com.goodving.guli.activity.WeightGoalSetActivity;
import com.goodving.guli.activity.ff;
import com.goodving.guli.activity.fh;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.C1154e;
import com.goodving.guli.bt.C1468p;
import com.goodving.guli.bt.C2056y;
import com.goodving.guli.bt.DimPanelFragment;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.eventbus.EventPersonInfoUpdate;
import com.goodving.guli.bt.eventbus.EventPersonInfoUpdateUnit;
import com.goodving.guli.bt.lua.DaoManager;
import com.goodving.guli.bt.lua.SlidingUpPanelLayout;
import com.goodving.guli.bt.model.BasicDateData;
import com.goodving.guli.bt.model.Birthday;
import com.goodving.guli.bt.model.C1495q;
import com.goodving.guli.bt.model.DataManager;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.model.WeightInfo;
import com.goodving.guli.bt.model.WeightInfoManager;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.XMBLEManager;
import com.goodving.guli.bt.ui.C1795p;
import com.goodving.guli.bt.ui.C1894O;
import com.goodving.guli.bt.utils.WeightUtil;
import com.goodving.guli.bt.weight.UserInfoManager;
import com.goodving.guli.bt.weight.WeightGoalManager;
import com.goodving.guli.bt.weight.family.dd;
import com.goodving.guli.model.DeviceSource;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.model.UserTotalSportData;
import com.goodving.guli.server.WebAPI;
import com.goodving.guli.server.WebResponse;
import com.goodving.guli.utility.C1481u;
import com.goodving.guli.utility.gulihardware.Constant;
import com.goodving.guli.view.BitmapDescriptorFactory;
import com.goodving.guli.view.C3247b;
import com.goodving.guli.view.C4220a;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpResponseHandler;

import org.json.JSONArray;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.concurrent.Executors;

import cn.com.smartdevices.bracelet.chart.util.ChartData;
import cn.com.smartdevices.bracelet.config.C0886a;
import cn.com.smartdevices.bracelet.config.Config;
import cz.msebera.android.httpclient.Header;
import de.greenrobot.event.EventBus;

/**
 * Created by john on 2016/1/3.
 */
public class MySettingFragment extends C1795p implements View.OnClickListener { // cM
    private static final String f9749Q = "TAG_FOR_SLIDINGPANEL";
    public static final int f9750b = 17;
    public static final int f9751c = 18;
    public static final String PERSON_INFO_JSON = "person_info_json";
    private static final long f9753e = 1000;
    private static final String TAG = "PersonInfoFragment";
    private static final int f9755h = 19;
    private static final int f9756i = 20;
    private ImageButton editMemberName;

    private TextView pageUid;
    private Bitmap f9762F;
    private View editArea;
    private Birthday mBirthday;
    private View setGoal;
    private TextView setGoalText;
    private SlidingUpPanelLayout settingSliding;
    private View weightGoal;
    private TextView weightGoalValue;
    private LinearLayout pageHeaderCenterArea;
    private int pageScrollParallax;
    private final SlidingUpPanelLayout.PanelSlideListener mSlidingListener;
    private Handler mHandler;
    private TextView genderValue;
    private TextView unitValue;
    private View gender;
    private TextView heightValue;
    private View height;
    private TextView weightValue;
    private View weight;
    private TextView ageValue;
    private View ageArea;
    private View unitSet;
    private final Config mConfig;
    private PersonInfo mPersonInfo;
    private View userInfoArea;
    private ImageButton personPageIcon;
    private TextView nickName;
    private TextView signature;
    private TextView location;
    private SessionManager session;

    class cT implements SlidingUpPanelLayout.PanelSlideListener {
        final /* synthetic */ MySettingFragment mySettingFragment;

        cT(MySettingFragment cMVar) {
            this.mySettingFragment = cMVar;
        }

        public int onGetPullDownDistance() {
            return 0;
        }

        public Boolean onGetPullDownDockEnable() {
            return Boolean.valueOf(false);
        }

        public float onGetThreshhold() {
            return 0.0f;
        }

        public float onGetThreshhold2() {
            return 0.0f;
        }

        public void onLastSlideOffset(View view, float f) {
            GuliLog.tracePrintInfo("TAG_FOR_SLIDINGPANEL", "onLastSlideOffset " + f);
        }

        public void onPanelAnchored(View view) {
            GuliLog.tracePrintInfo("TAG_FOR_SLIDINGPANEL", "onPanelAnchored");
        }

        public void onPanelCollapsed(View view) {
            GuliLog.tracePrintInfo("TAG_FOR_SLIDINGPANEL", "onPanelCollapsed");
        }

        public void onPanelExpanded(View view) {
            GuliLog.tracePrintInfo("TAG_FOR_SLIDINGPANEL", "onPanelExpanded");
        }

        public void onPanelSlide(View view, Boolean bool, float f) {
        }
    }

    public MySettingFragment() {
        this.mConfig = Config.m8876h();
        this.mPersonInfo = null;
        this.mSlidingListener = new cT(this);
    }

    private float m14542a(float f) {
        return (f < 0.0f || ((double) f) >= 0.3d) ? (((double) f) < 0.3d || f >= 1.0f) ? 0.0f : 0.0f : 1.0f - (3.3333333f * f);
    }

    private void initView(View view) {
        this.pageScrollParallax = getResources().getDimensionPixelSize(R.dimen.person_page_scroll_parallax);
        this.genderValue = (TextView) view.findViewById(R.id.info_gender_value);
        this.gender = view.findViewById(R.id.info_gender);
        this.gender.setOnClickListener(this);
        this.heightValue = (TextView) view.findViewById(R.id.info_height_value);
        this.height = view.findViewById(R.id.info_height);
        this.height.setOnClickListener(this);
        this.weightValue = (TextView) view.findViewById(R.id.info_weight_value);
        this.weight = view.findViewById(R.id.info_weight);
        this.weight.setOnClickListener(this);
        this.ageValue = (TextView) view.findViewById(R.id.info_age_value);
        this.ageArea = view.findViewById(R.id.info_age_area);
        this.ageArea.setOnClickListener(this);
        this.unitSet = view.findViewById(R.id.info_unit_set);
        this.unitSet.setOnClickListener(this);
        this.unitValue = (TextView) view.findViewById(R.id.info_unit_value);
        this.setGoalText = (TextView) view.findViewById(R.id.device_set_goal_text);
        this.setGoal = view.findViewById(R.id.device_set_goal);
        this.setGoal.setOnClickListener(this);
        this.weightGoal = view.findViewById(R.id.info_weight_goal);
        this.weightGoal.setOnClickListener(this);
        if (!Config.m8876h().f4202l.f4259a.booleanValue()) {
            this.weightGoal.setVisibility(View.GONE);
        }
        this.weightGoalValue = (TextView) view.findViewById(R.id.info_weight_goal_value);
        view.findViewById(R.id.mili_exit_login).setOnClickListener(this);
        this.userInfoArea = view.findViewById(R.id.person_info_user_info_area);
        this.editArea = view.findViewById(R.id.person_info_edit_area);
        if (Keeper.readPersonInfo().uid == this.mPersonInfo.uid) {
            this.editArea.setVisibility(View.VISIBLE);
        } else {
            this.editArea.setVisibility(View.GONE);
        }

//        m14557h();
        m14559i();
    }

    private void m14544a(PersonInfo personInfo) {
        int i;
        int i2 = 0;
        if (personInfo.height < 40 || personInfo.height > C4220a.an) {
            personInfo.height = C4220a.aC;
            i = 0;
        } else {
            i = 1;
        }
        if (personInfo.weight < 3.0f || personInfo.weight > ((float) (WeightUtil.m15718c(getActivity()) + 1))) {
            personInfo.weight = BitmapDescriptorFactory.HUE_YELLOW;
            i = 0;
        }
        if (personInfo.gender < 0) {
            personInfo.gender = 1;
        } else {
            i2 = i;
        }
        if (i2 == 0) {
            Keeper.keepPersonInfo(personInfo);
        }
    }

    private void m14547b(String str) {
        if (!TextUtils.isEmpty(str)) {
            this.mBirthday = Birthday.fromStr(str);
        }
        if (this.mBirthday == null || !this.mBirthday.isValid()) {
            int age = this.mPersonInfo.getAge();
            if (age > 0) {
                int i = Calendar.getInstance().get(Calendar.YEAR);
                this.mPersonInfo.setVersion(1);
                String str2 = (i - age) + "-1";
                GuliLog.tracePrintInfo(TAG, "update age " + age + "to birth:" + str2);
                this.mPersonInfo.setBirthday(str2);
                Keeper.keepPersonInfo(this.mPersonInfo);
                onEvent(new EventPersonInfoUpdate(str2));
                this.mBirthday = Birthday.fromStr(str2);
            }
            GuliLog.tracePrintInfo(TAG, "updated birthday  = " + this.mBirthday);
            return;
        }
        GuliLog.tracePrintInfo(TAG, "cur birthday  = " + this.mBirthday);
        this.mPersonInfo.setAge(this.mBirthday.getAge());
        Keeper.keepPersonInfo(this.mPersonInfo);
    }

    public static Fragment m14548c() {
        Fragment cMVar = new MySettingFragment();
        Bundle bundle = new Bundle();
        Object readPersonInfo = Keeper.readPersonInfo();
        if (readPersonInfo != null) {
            bundle.putString(PERSON_INFO_JSON, new Gson().toJson(readPersonInfo));
        }
        cMVar.setArguments(bundle);
        return cMVar;
    }

    class cN extends AsyncHttpResponseHandler {
        final /* synthetic */ MySettingFragment f9793a;

        cN(MySettingFragment cMVar) {
            this.f9793a = cMVar;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.m12370d("MySettingFragment", "unbind weixin onFailure:" + i + ", " + Utils.m8035b(bArr));
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            GuliLog.m12370d("MySettingFragment", "onSuccess:" + i + "," + Utils.m8035b(bArr));
        }
    }

    private void m14551e() {
        GuliLog.m12360b(TAG, "exit login now!");
        if (getActivity() == null) {
            GuliLog.m12370d(TAG, "exit login now! but the context is null!");
            return;
        }
        Utils.m7993a(getActivity(), (int) R.string.mili_exit_login_info_exiting, false);
        WebAPI.m11634d(C0886a.m9071f(getActivity()), C0886a.m9069d(getActivity()), new cN(this));
        m14553f();
    }

    class cQ implements C1468p {
        final /* synthetic */ MySettingFragment f9796a;

        cQ(MySettingFragment cMVar) {
            this.f9796a = cMVar;
        }

        public void m12295a(UserTotalSportData userTotalSportData) {
            GuliLog.tracePrintInfo("MySettingFragment", "returnSportData");
            this.f9796a.mPersonInfo.totalSportData = userTotalSportData;
            Keeper.keepPersonInfo(this.f9796a.mPersonInfo);
            this.f9796a.m14569r();
        }
    }

    class cP implements Runnable {
        final /* synthetic */ LoginOutHandler f9795a;

        cP(LoginOutHandler cOVar) {
            this.f9795a = cOVar;
        }

        public void run() {
            this.f9795a.f9794a.m14574w();
            Utils.m7991a(this.f9795a.f9794a.getActivity());
            this.f9795a.f9794a.restartLogin();
        }
    }

    class LoginOutHandler extends AsyncHttpResponseHandler {
        final /* synthetic */ MySettingFragment f9794a;

        LoginOutHandler(MySettingFragment cMVar) {
            this.f9794a = cMVar;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.m12370d("MySettingFragment", "logout onFailed: status= " + i + Utils.m8035b(bArr));
            Utils.m7991a(this.f9794a.getActivity());
            this.f9794a.loginOutFailure();
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            GuliLog.m12370d("MySettingFragment", "loginOut:" + Utils.m8035b(bArr));
            new Handler().postDelayed(new cP(this), 1);
        }
    }

    private void m14553f() {
        WebAPI.m11641g(C0886a.m9071f(getActivity()), new LoginOutHandler(this));
    }

    private void m14556g() {
        DataManager.m12179a().m12205a(new cQ(this));
    }

    private void m14557h() {
        fh a = new ff(getActivity()).m14851a();
        if (a.m14878d()) {
            int e = a.m14879e();
            int dimensionPixelSize = getResources().getDimensionPixelSize(R.dimen.person_fragment_panel);
            GuliLog.tracePrintInfo(TAG, "SlidingPanel SystemBarH : " + e + ", OriginalPanelH : " + dimensionPixelSize);
            this.settingSliding.setPanelHeight(dimensionPixelSize - e);
        }
    }

    private void m14559i() {
        this.personPageIcon = (ImageButton) this.userInfoArea.findViewById(R.id.person_page_icon);
        this.personPageIcon.setOnClickListener(this);
        this.nickName = (TextView) this.userInfoArea.findViewById(R.id.person_page_nickname);
        this.nickName.setOnClickListener(this);
        this.signature = (TextView) this.userInfoArea.findViewById(R.id.person_page_signature);
        this.location = (TextView) this.userInfoArea.findViewById(R.id.person_page_location);
        this.location.setOnClickListener(this);
        this.editMemberName = (ImageButton) this.userInfoArea.findViewById(R.id.edit_member_name);
        this.editMemberName.setOnClickListener(this);
        this.pageUid = (TextView) this.userInfoArea.findViewById(R.id.person_page_uid);
        this.pageHeaderCenterArea = (LinearLayout) this.userInfoArea.findViewById(R.id.person_page_header_center_area);

    }

    static public class cB extends DimPanelFragment {
        private int resourceId;

        public cB() {
            this.resourceId = 0;
        }

        protected int inflateLayout() {
            this.resourceId = getArguments().getInt(Constant.aR);
            return this.resourceId == 0 ? R.layout.fragment_mili_exit_login : this.resourceId == 1 ? R.layout.fragment_mili_exit_login_continue : R.layout.fragment_unbind_mili_exit_login;
        }

        public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
            View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
            if (this.resourceId == 0) {
                TextView textView = (TextView) onCreateView.findViewById(R.id.mili_exit_login_info_tv);
                String string = getString(R.string.mili_exit_login_info_unbind);
                String string2 = getString(R.string.mili_exit_login_info_unlock);
                String string3 = getString(R.string.mili_exit_login_info_continue_tip);
                textView.setText(C1757t.m13470c(getActivity()) ? string + string2 + string3 : string + string3);
            }
            return onCreateView;
        }
    }

    class cR implements C1154e {
        final /* synthetic */ MySettingFragment mySettingFragment;

        cR(MySettingFragment MySettingFragment) {
            this.mySettingFragment = MySettingFragment;
        }

        public void m10600a(DialogFragment dialogFragment) {
        }

        public void m10601b(DialogFragment dialogFragment) {
            dialogFragment.dismiss();
            this.mySettingFragment.m14564m();
//            C1497A.m12380a().m12402b();
//            C1961v.m15506a().m15521i(this.mySettingFragment.getActivity());
            C0668a.m8128a(this.mySettingFragment.getActivity(), C0668a.dZ, C0668a.dC);
        }

        public void m10602c(DialogFragment dialogFragment) {
            dialogFragment.dismiss();
            C0668a.m8128a(this.mySettingFragment.getActivity(), C0668a.dZ, C0668a.dD);
        }
    }


    private void m14561j() {
        cB cBVar = new cB();
        Bundle bundle = new Bundle();
        if (DeviceSource.hasBindBracelet()) {
            bundle.putInt(Constant.aR, 0);
        } else {
            bundle.putInt(Constant.aR, 2);
        }
        cBVar.setArguments(bundle);
        cBVar.setOpClickListener(new cR(this));
        DimPanelFragment.showPanel(getActivity(), cBVar);
    }

    private void m14562k() {
//        if (C0634B.m7841a().m7862f()) {
//            C0634B.m7841a().m7849a(Keeper.readBraceletBtInfo().f19636b);
//        }
//        SwitchOperator readSwitchOperator = Keeper.readSwitchOperator();
        boolean readShowedUserAgreement = Keeper.readShowedUserAgreement();
        SharedPreferences.Editor edit = Keeper.getSharedPref().edit();
        edit.clear();
        edit.commit();
//        Keeper.keepSwitchOperator(readSwitchOperator);
        Keeper.keepShowedUserAgreement(readShowedUserAgreement);
        DaoManager.getInstance().getLuaListDao().deleteAll();
        DaoManager.getInstance().getLuaZipFileDao().deleteAll();
        DataManager.m12179a().m12213b();
        // GPS
//        C0910a.m9175a(getActivity());
//        C1571a.m12588b(getActivity());
        WeightGoalManager.getInstance().m15893b();
        UserInfoManager.getInstance().deleteAllInfos();
        WeightInfoManager.getInstance().deleteAllInfos();
        Keeper.keepScaleSyncedUserInfosFromServer(false);
        Keeper.keepScaleSyncedWeightInfosFromServer(false);
        Keeper.setHeartRateDataFromServer(false);
        Keeper.keepWeightCurrentUserAsync(-1);
//        if (this.mConfig.f4193c.f4248d.booleanValue()) {
//            QQLogin.getInstance(getActivity().getApplicationContext()).clean(false);
//            QQHealth.getInstance(getActivity().getApplicationContext()).clean(false);
//        }
    }

    private void restartLogin() {
        if (getActivity() != null) {

            //  TBD
            session.setLogin(false);
            Intent intent = new Intent();
            intent.setClass(getActivity(), LoginActivity.class);
            intent.setFlags(268468224);
            startActivity(intent);
        }
    }


    class cW implements Runnable {
        final /* synthetic */ Boolean f9802a;
        final /* synthetic */ cV f9803b;

        cW(cV cVVar, Boolean bool) {
            this.f9803b = cVVar;
            this.f9802a = bool;
        }

        public void run() {
            Utils.m7991a(this.f9803b.mySettingFragment.getActivity());

            //   TBD;
            m14574w();
            restartLogin();

            if (this.f9802a.booleanValue()) {
                this.f9803b.mySettingFragment.m14551e();
            } else {
                // failed to sync up with server for login out
                this.f9803b.mySettingFragment.m14573v();
            }
        }
    }

    final class cY {
        public boolean mStatus;
        final /* synthetic */ cV f9807b;

        private cY(cV cVVar) {
            this.f9807b = cVVar;
            this.mStatus = true;
        }
    }

    class cX extends AsyncHttpResponseHandler {
        final /* synthetic */ cY f9804a;
        final /* synthetic */ cV f9805b;

        cX(cV cVVar, cY cYVar) {
            this.f9805b = cVVar;
            this.f9804a = cYVar;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            this.f9804a.mStatus = false;
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            WebResponse a = WebResponse.getWebResponse(this.f9805b.mySettingFragment.getActivity(), Utils.m8035b(bArr));
            this.f9804a.mStatus = a.m11659c();
        }
    }

    final class cV extends AsyncTask<Void, Integer, Boolean> {
        final /* synthetic */ MySettingFragment mySettingFragment;

        private cV(MySettingFragment cMVar) {
            this.mySettingFragment = cMVar;
        }

        protected Boolean m14589a(Void... voidArr) {
            GuliLog.m12370d("MySettingFragment", "start doInBackground");
            if (Utils.m8084k(this.mySettingFragment.getActivity())) {
                cY cYVar = new cY(this);
                C1495q c1495q = new C1495q();
                ArrayList a = DataManager.m12179a().m12203a(c1495q);
                if (a != null && a.size() > 0) {
                    JSONArray jSONArray = new JSONArray();
                    Iterator it = a.iterator();
                    while (it.hasNext()) {
                        jSONArray.put(((BasicDateData) it.next()).toJSONObject());
                    }
                    WebAPI.m11623b(C0886a.m9071f(this.mySettingFragment.getActivity()), C0886a.m9069d(this.mySettingFragment.getActivity()), c1495q, jSONArray.toString(), new cX(this, cYVar));
                }
                GuliLog.m12370d("MySettingFragment", "basic data result.mIsSucceeded = " + cYVar.mStatus);
//                cYVar.mStatus &= C1228b.m11433a(this.mySettingFragment.getActivity()).m11441b();
//                GuliLog.m12370d("MySettingFragment", "heartrate data result.mIsSucceeded = " + cYVar.mStatus);
//                cYVar.mStatus &= C1364i.m11812a(this.mySettingFragment.getActivity(), null);
//                GuliLog.m12370d("MySettingFragment", "sport data result.mIsSucceeded = " + cYVar.mStatus);
//                cYVar.mStatus &= C1647J.m13014b(this.mySettingFragment.getActivity());
//                GuliLog.m12370d("MySettingFragment", "shoes data result.mIsSucceeded = " + cYVar.mStatus);

                // TBD hack here, to think we enable weight by default
//                if (Config.m8876h().f4202l.f4259a.booleanValue()) {
                cYVar.mStatus &= WeightUtil.syncWithServer(this.mySettingFragment.getActivity());
                GuliLog.m12370d("MySettingFragment", "weight data result.mIsSucceeded = " + cYVar.mStatus);
//                }
                GuliLog.m12370d("MySettingFragment", "end doInBackground\uff0csucess:" + cYVar.mStatus);
                return Boolean.valueOf(cYVar.mStatus);
            }
            return Boolean.valueOf(!this.mySettingFragment.m14578d());
        }

        public void m14590a(Boolean bool) {
            GuliLog.m12370d("MySettingFragment", "onPostExecute");
            if (this.mySettingFragment.getActivity() != null) {
                this.mySettingFragment.mHandler.postDelayed(new cW(this, bool), 1000);
            }
        }

        protected /* synthetic */ Boolean doInBackground(Void[] objArr) {
            return m14589a((Void[]) objArr);
        }

        public void onCancelled() {
            Utils.m7991a(this.mySettingFragment.getActivity());
        }

        public /* synthetic */ void onPostExecute(Boolean obj) {
            m14590a((Boolean) obj);
        }

        public void onPreExecute() {
            super.onPreExecute();
            Utils.m7993a(this.mySettingFragment.getActivity(), (int) R.string.sync_to_server, false);
            GuliLog.m12370d("MySettingFragment", "onPreExecute");
        }
    }

    private void m14564m() {
        if (getActivity() != null) {
            new cV(this).executeOnExecutor(Executors.newScheduledThreadPool(1), new Void[0]);
        }
    }

    private void m14565n() {
        if (DeviceSource.hasBindBracelet()) {
//            new C3834v(Utils.m7973a(this.mPersonInfo), new cS(this)).m9824f();
        } else {
            GuliLog.tracePrintInfo(TAG, "Has not bind band!");
        }
    }

    private void m14566o() {
        Utils.m8007a(this.mPersonInfo, this.personPageIcon);
    }

    private void m14567p() {
        this.setGoalText.setText(this.mPersonInfo.getDaySportGoalSteps() + getString(R.string.step_per_day));
    }

    private void m14568q() {
        m14566o();
        m14569r();
    }

    private void m14569r() {
        if (getActivity() != null) {
            this.nickName.setText(this.mPersonInfo.nickname);
            this.signature.setText(this.mPersonInfo.personSignature);
            this.pageUid.setText(String.valueOf(this.mPersonInfo.uid));


        }
    }

    private void updateUi() {
        GuliLog.tracePrintInfo(TAG, "update UI: " + this.mPersonInfo.totalSportData + ", " + this.mPersonInfo);
        GuliLog.tracePrintInfo(TAG, "updateUI mpersoninfo weight " + this.mPersonInfo.weight);
        m14544a(this.mPersonInfo);
        if (getActivity() == null) {
            GuliLog.tracePrintError(TAG, "getActivity is null");
            return;
        }
        this.genderValue.setText(this.mPersonInfo.gender == 1 ? getString(R.string.male) : getString(R.string.female));
        m14571t();
        WeightInfo a = WeightInfoManager.getInstance().m15743a(-1, 0);
        GuliLog.tracePrintInfo("PERSON_WEIGHT", "person info .weight " + this.mPersonInfo.weight);
        float b = WeightUtil.m15706b(this.mPersonInfo.weight, this.mPersonInfo.miliConfig.weightUnit);
        if (a != null) {
            b = WeightUtil.m15706b(a.weight, this.mPersonInfo.miliConfig.weightUnit);
        }
        this.weightValue.setText(WeightUtil.m15716c(b, 1) + WeightUtil.m15698a(getActivity().getApplicationContext(), this.mPersonInfo.miliConfig.weightUnit));
        this.mBirthday = Birthday.fromStr(this.mPersonInfo.getBirthday());
        if (this.mBirthday != null) {
            this.ageValue.setText(this.mBirthday.toString());
        }
        if (this.mPersonInfo.targetWeight > 0.0f) {
            this.weightGoalValue.setText(((int) WeightUtil.m15706b(this.mPersonInfo.targetWeight, this.mPersonInfo.miliConfig.weightUnit)) + WeightUtil.m15698a(getActivity().getApplicationContext(), this.mPersonInfo.miliConfig.weightUnit));
        } else {
            this.weightGoalValue.setText("");
        }
        m14568q();
    }

    private void m14571t() {
        this.unitValue.setText(this.mPersonInfo.getUnit() == 0 ? getString(R.string.unit_metric) : getString(R.string.unit_british));
        this.heightValue.setText(m14572u());
    }

    private String m14572u() {
        int i = this.mPersonInfo.height;
        int a = C2056y.m15946a(i);
        if (this.mPersonInfo.getUnit() == 0) {
            return i + getString(R.string.cm);
        }
        String quantityString = getResources().getQuantityString(R.plurals.numberFoot, a / 12, new Object[]{Integer.valueOf(a / 12)});
        return quantityString + " " + getResources().getQuantityString(R.plurals.numberInch, a % 12, new Object[]{Integer.valueOf(a % 12)});
    }

    static public class cC extends DimPanelFragment {
        protected int inflateLayout() {
            return R.layout.diaglog_exit_sync_failed;
        }
    }

    class cU implements C1154e {
        final /* synthetic */ MySettingFragment f9800a;

        cU(MySettingFragment cMVar) {
            this.f9800a = cMVar;
        }

        public void m10600a(DialogFragment dialogFragment) {
        }

        public void m10601b(DialogFragment dialogFragment) {
        }

        public void m10602c(DialogFragment dialogFragment) {
            dialogFragment.dismiss();
            this.f9800a.m13556a();
        }
    }

    private void m14573v() {
        cC cCVar = new cC();
        DimPanelFragment.showPanel(getActivity(), cCVar);
        cCVar.setOpClickListener(new cU(this));
    }

    private void m14574w() {
        Utils.m8053c(getActivity(), 1);
        m14562k();
        XMBLEManager.m25155b();
        XMBLEManager.m25163h();
        if (Config.m8876h().f4194d.f4252a.booleanValue() && getActivity() != null) {
//            C1492h.m12327a(getActivity()).m12336b();
        }
        m14576y();
    }

    private void loginOutFailure() { // m14575x
        C3247b.m22928a(getActivity(), (int) R.string.logout_failed_retry, 0).show();
    }

    private void m14576y() {
        ((NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
    }

    protected boolean m14577b() {
        return true;
    }

    public boolean m14578d() {
        ArrayList a = DataManager.m12179a().m12203a(new C1495q());
        // boolean z = (a == null || a.size() == 0) && WeightInfoManager.getInstance().m15780f().isEmpty() && WeightInfoManager.getInstance().m15772d().isEmpty() && !C1364i.m11811a(getActivity()) && !C1647J.m13009a(getActivity());
        boolean z = (a == null || a.size() == 0) && WeightInfoManager.getInstance().m15780f().isEmpty()
                && WeightInfoManager.getInstance().m15772d().isEmpty();

        GuliLog.m12370d(TAG, "checkDataNeedSync:" + (!z));
        return !z;
    }

    @SuppressLint({"NewApi"})
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == f9750b && intent != null) {
            this.mPersonInfo.avatarPath = intent.getStringExtra("CROPPED_FILE_PATH");
            m14568q();
            this.mPersonInfo.setNeedSyncServer(1);
            Keeper.keepPersonInfo(this.mPersonInfo);
            GuliLog.tracePrintInfo(TAG, "onActivityResult requst_code =" + i);
            EventBus.getDefault().post(new EventPersonInfoUpdate(EventPersonInfoUpdate.UPDATE_AVATAR));
        } else if (i == f9751c && intent != null && intent.getExtras() != null) {
            this.f9762F = (Bitmap) intent.getExtras().get("data");
            if (this.f9762F != null) {
                try {
                    String str = Utils.m8079j(getActivity().getApplicationContext()) + "/bracelet_icon.jpg";
                    OutputStream fileOutputStream = new FileOutputStream(str);
                    this.f9762F.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
                    fileOutputStream.close();
                    this.mPersonInfo.avatarPath = str;
                    this.personPageIcon.setBackground(new BitmapDrawable(getResources(), C1894O.m15165a(this.f9762F)));
                    this.f9762F.recycle();
                    this.f9762F = null;
                    this.mPersonInfo.setNeedSyncServer(1);
                    Keeper.keepPersonInfo(this.mPersonInfo);
                    GuliLog.tracePrintInfo(TAG, "onActivityResult requst_code =" + i + " task photo post evnetbus");
                    EventBus.getDefault().post(new EventPersonInfoUpdate(EventPersonInfoUpdate.UPDATE_AVATAR));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (i == f9755h) {
            if (intent != null && intent.getExtras() != null) {
                this.mPersonInfo.setDaySportGoals(intent.getExtras().getInt(C4220a.ct, this.mPersonInfo.getDaySportGoalSteps()));
                m14568q();
            }
        } else if (f9756i != i) {
        } else {
            if (WeightGoalSetActivity.f11180c == i2) {
                EventBus.getDefault().post(new EventPersonInfoUpdate(null));
            } else if (WeightGoalSetActivity.f11181d == i2) {
                float floatExtra = intent.getFloatExtra(WeightGoalSetActivity.f11179b, 0.0f);
                this.mPersonInfo.targetWeight = WeightUtil.m15689a(floatExtra, Keeper.readPersonInfo().miliConfig.weightUnit);
                EventBus.getDefault().post(new EventPersonInfoUpdate(null));
            }
        }
    }

    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.info_nick_name:
                DimPanelFragment.showPanel(getActivity(), NickNamePanelFragment.m14664a(-1).getClass());
                break;
            case R.id.info_person_signature:
                DimPanelFragment.showPanel(getActivity(), SignaturePanelFragment.class);
                break;
            case R.id.info_gender:
                DimPanelFragment.showPanel(getActivity(), dd.m14648a(-1).getClass());
                break;
            case R.id.info_age_area:
                DimPanelFragment.showPanel(getActivity(), AgePanelFragment.m14642a(-1).getClass());
                break;
            case R.id.info_height:
                DimPanelFragment.showPanel(getActivity(), HeightPanelFragment.m14650a(-1).getClass());
                break;
            case R.id.info_weight:
                if (Config.m8876h().f4202l.f4259a.booleanValue()) {
                    intent = new Intent(getActivity(), StatisticActivity.class);
                    intent.putExtra(ChartData.KEY_MODE, PersonInfo.INCOMING_CALL_DISABLE_BIT);
                    intent.putExtra("FROM_PERSONINFO_FRAGMENT", true);
                    getActivity().startActivity(intent);
                    return;
                }
                DimPanelFragment.showPanel(getActivity(), WeightPanelFragment.m14666a(-1).getClass());
                break;
            case R.id.device_set_goal:
                startActivityForResult(new Intent(getActivity(), HealthGoalsActivity.class), f9755h);
                break;
            case R.id.edit_member_name:
            case R.id.person_page_nickname:
                DimPanelFragment.showPanel(getActivity(), NickNamePanelFragment.m14664a(-1).getClass());
                break;
            case R.id.info_weight_goal:
                intent = new Intent(getActivity(), WeightGoalSetActivity.class);
                intent.putExtra(WeightGoalSetActivity.f11178a, -1);
                getActivity().startActivityForResult(intent, f9756i);
                break;
            case R.id.info_unit_set:
                startActivity(new Intent(getActivity(), PersonInfoSettingUnitActivity.class));
                break;
            case R.id.mili_exit_login:
                if (Utils.m8084k(getActivity())) {
                    m14561j();
                    return;
                }
                C3247b.m22928a(getActivity(), (int) R.string.no_network_connection, 0).show();
                m13556a();
                break;
            case R.id.person_page_icon:
                DimPanelFragment.showPanel(getActivity(), PersonIconPanelFragment.class);
                break;
            default:
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        PersonInfo personInfo = new Gson().fromJson(getArguments().getString(PERSON_INFO_JSON), PersonInfo.class);
        GuliLog.tracePrintInfo(TAG, "this person=" + personInfo);
        this.mPersonInfo = personInfo;
        EventBus.getDefault().register(this);
        this.mHandler = new Handler();

        // session manager
        session = new SessionManager(C1481u.getContext());

    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        GuliLog.tracePrintInfo(TAG, "onCreateView");
        View inflate = layoutInflater.inflate(R.layout.activity_my_setting, null);
        initView(inflate);
//        m14556g();
        return inflate;
    }

    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public void onEvent(EventPersonInfoUpdate eventPersonInfoUpdate) {
        this.mPersonInfo = Keeper.readPersonInfo();
        GuliLog.tracePrintInfo(TAG, "update ... ui " + this.mPersonInfo);
        if (!EventPersonInfoUpdate.UPDATE_AVATAR.equals(eventPersonInfoUpdate.type)) {
            updateUi();
            m14565n();
        }
        Utils.m7998a(getActivity(), this.mPersonInfo);
    }

    public void onEvent(EventPersonInfoUpdateUnit eventPersonInfoUpdateUnit) {
        this.mPersonInfo = Keeper.readPersonInfo();
        m14571t();
        Utils.m7998a(getActivity(), this.mPersonInfo);
    }

    public void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.f3563f);
    }

    public void onResume() {
        super.onResume();
        m14567p();
        m14547b(this.mPersonInfo.getBirthday());
        if (this.mPersonInfo.getNeedSyncServer() != 0) {
            onEvent(new EventPersonInfoUpdate(null));
        } else {
            updateUi();
        }
        C0668a.m8133a(C0668a.f3563f);
    }
}